//
//  ZMSearchHeaderVeiw.m
//  CenturyCity
//
//  Created by beisheng03 on 2017/12/20.
//  Copyright © 2017年 beisheng. All rights reserved.
//

#import "ZMSearchHeaderVeiw.h"

@interface ZMSearchHeaderVeiw ()
@property (weak, nonatomic) IBOutlet UILabel *leftLabel;
@property (weak, nonatomic) IBOutlet UIButton *rightBtn;
@property (weak, nonatomic) IBOutlet UIView *bgView;

@end

@implementation ZMSearchHeaderVeiw

- (void)awakeFromNib {
    [super awakeFromNib];
    self.leftLabel.font = MYFONT(15);
    
    self.bgView.backgroundColor = [UIColor whiteColor];
    
    [self.rightBtn setTitleColor:darkGray forState:UIControlStateNormal];
    [self.rightBtn setTitleColor:darkGray forState:UIControlStateHighlighted];

    self.rightBtn.titleLabel.font = MYFONT(13);
    
    // Initialization code
}

- (void)setIsHidenBtn:(BOOL)isHidenBtn{
    
    _isHidenBtn = isHidenBtn;
    
    
    self.rightBtn.hidden = _isHidenBtn;
    
    if (_isHidenBtn) {
        
        if ([self.type isEqualToString:@"1"]) {
            
            self.leftLabel.text = @"企业分类";
            
        } else if ([self.type isEqualToString:@"2"]){
            
            self.leftLabel.text = @"职业分类";
            
        }else{
            
            self.leftLabel.text = @"";
            
        }
        
        
        
    } else {
        
        self.leftLabel.text = @"搜索历史";

    }
    

}

- (IBAction)rightBtnDidTap:(UIButton *)sender {
    
    
    UIAlertController *contr = [UIAlertController alertControllerWithTitle:nil message:@"确定清空历史吗?" preferredStyle:UIAlertControllerStyleAlert];
    
//    MJWeakSelf;
    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        
        [myViewModel.searchHistory.searchHistoryStrs removeAllObjects];
        
        UICollectionViewController *collectionVC = (UICollectionViewController *)self.viewController;
        
        [collectionVC.collectionView endEditing:YES];
        
        
        [collectionVC.collectionView reloadData];
        
    }];
    
    
    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
    }];
    
    
    [contr addAction:action2];
    [contr addAction:action1];
    
    [self.viewController presentViewController:contr animated:YES completion:nil];
    
  
    
    
}

@end
